package models

import "gorm.io/gorm"

type PractiseChapterRecord struct {
	Id        int `json:"id" gorm:"primaryKey;autoIncrement;comment:主键编码"` // 课程ID
	StudentId int `json:"studentId"`
	ChapterId int `json:"chapterId"`
}

func (record *PractiseChapterRecord) TableName() string {
	return "practise_chapter_record"
}

func (record *PractiseChapterRecord) GetRecordsByChapterIds(db *gorm.DB, studentID int, chapterIds []int) map[int]bool {
	lists := make([]*PractiseChapterRecord, 0)
	db.Where("student_id = ?", studentID).Where("chapter_id in (?)", chapterIds).Find(&lists)
	chapterId2has := make(map[int]bool)
	for _, l := range lists {
		chapterId2has[l.ChapterId] = true
	}
	return chapterId2has
}
